<?php

namespace App\Api;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Auth;

class LoginController extends Controller
{

    public function login(Request $request)
    {
        $isLogin = Auth::attempt(['mobile' => $request->mobile, 'password' => $request->password]);
        if ($isLogin) {
            $token = Auth::user()->createToken('token-name');
            return ['message' => '登录成功', 'token' => $token->plainTextToken];
        }
        return $this->error('账号或者密码错误');
    }

    public function logout()
    {
        Auth::logout();
        return $this->message('退出成功');
    }
}
